# -*- mode: snippet -*-
# name: median time of survfit for tidymodels/broom
# key: survfit_median_time
# contributor: Shuguang Sun
# --
survfit_median_time <- function(x, ...) {
  # x from survfit
  # t for single arm
  md <- t(as.data.frame(summary(x)$table)) |>
    as.data.frame() |>
    dplyr::select(
      median, ends_with("LCL"), ends_with("UCL")
    )
  # for single arm
  rownames(md) <- "All"
  # multiple rows if not single arm
  colnames(md) <- c("median", "lower", "upper")
  ret <- list(median = md$median, median_lower = md$lower,
              median_upper = md$upper
              )
  as_tibble(ret)
}
